package com.zjmcollege.hotpot.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * @author zpym
 * @CopyRight (C) http://www.iengoo.com
 * @brief 资源映射路径
 * @email 122162005@qq.com
 * @date 2019-11-06 21:52
 */
@Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {
    @Autowired
    private Config config;
    /**
     * 处理静态文件
     * MVC配置使http://IP:端口号/${server.context-path}/profile/图片路径可以访问到配置的文件夹
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/" + config.getImgUriPattern() + "/**",
                "/" + config.getAttachUriPattern() + "/**").addResourceLocations("file:" +
                        config.getFilePath() + "images\\", "file:" + config.getFilePath() +
                config.getAttachUriPattern() + "\\");
    }

    /**
     * If you want to use @ServerEndpoint in a Spring Boot application that used an embedded container,
     * you must declare a single ServerEndpointExporter @Bean, as shown in the following example:
     * [prɪˈsiːdɪŋ]
     *
     * @return
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}
